package Day11;

import java.util.Scanner;

/**
 * @author HYHwtx
 * @version 1.0
 * @date 2022/2/17 9:16
 */
public class Test10 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int [] array = {10,5,7,13,92,22,37,61,1,12};
        int []a = new int[array.length+1];
        System.out.println("请输入要增加的数字:");
        int num = in.nextInt();
        //记录位置
        int min = 0;
        int max = array.length-1;
        int mid = (min+max)/2;

        while(min<=max) {

            if (num >= array[mid]) {
                min = mid + 1;
                mid = (min + max) / 2;
            } else if (num < array[mid]) {
                max = mid - 1;
                mid = (min + max) / 2;
            }
        }
        //当min>max时,就意味着要插入的数字在二者指向的对象之间
        //在max之后min之前
        //将数组放到新数组中
        for(int i = 0;i<min;i++){
            a[i] = array[i];
        }
        a[min] = num;

        for(int i = min;i<array.length;i++){
            a[i+1] = array[i];
        }
        //打印插入后的数组
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i]+" ");
        }

    }
}
